package com.zhuss.core.processor;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

import com.zhuss.bean.bo.core.orign.DeleteOrignBo;
import com.zhuss.common.AbstractProcessor;
import com.zhuss.common.Processor;
import com.zhuss.core.db.dao.ext.OrignDao;
import com.zhuss.core.db.entity.Orign;
import com.zhuss.db.entity.OpLog;
import com.zhuss.enums.LogActionEnum;
import com.zhuss.enums.MoudleEnum;
import com.zhuss.exception.AabException;
import com.zhuss.util.JsonUtil;

/**
 * 删除orign processor
 * @Author: zhushanshuo
 * @Date: 2020/02/20 21:55
 */
@Component("orignDelete")
public class OrignDelete extends AbstractProcessor<Object, DeleteOrignBo> implements Processor<Object, DeleteOrignBo> {

    @Autowired
    private OrignDao orignDao;
    
    @Autowired
	@Qualifier("orignRead")
	private OrignRead orignRead;
    
    /**
     * 校验
     */
	@Override
    public void check(DeleteOrignBo bo) throws AabException {
    }
    
    /**
     * 操作方法
     */
    @Override
    public Object process(DeleteOrignBo param) throws AabException {
    	Long orignId = param.getOrignId();
    	
    	Orign record = new Orign();
    	record.setOrignId(orignId);
    	record.setDeleted(param.getDeleted());
    	
    	record.setModifierId(param.getConcurrentUserId());
    	record.setModifier(param.getConcurrentUserName());
    	record.setModifyTime(new Date());
    	orignDao.delete(record);
        return null;
    }
    
    /**
     * 操作日志
     */
	@Override
	public Object log(DeleteOrignBo param) throws AabException {
		OpLog record = new OpLog();
    	record.setMoudle(MoudleEnum.基础模块.key());
    	record.setAction(LogActionEnum.orign删除.key());
    	record.setTargetId(param.getOrignId());
    	record.setTargetName(param.getName());
    	record.setContent("参数: " + JsonUtil.toJson(param));
    	record.setReason(param.getExceptionReason());
    	
    	record.setCreatorId(param.getConcurrentUserId());
    	record.setCreator(param.getConcurrentUserName());
    	record.setCreateTime(new Date());
    	log(record);
    	return null;
	}
}
